<?php

require_once('mysql_table.php');

class producto extends mysql_table {

  function __construct() {
    parent::__construct();
    $this->TableName = "PRODUCTOS";
    $this->IDField = "ID";

    $this->fields['ID'] = "";
    $this->fields['DESCRIPCION'] = "";
    $this->fields['DESCRIPCION_ADMIN'] = "";
    $this->fields['ORDEN'] = "";
    $this->fields['ID_STATUS'] = "";
  }

  /*
   * @return los activos
   * */

  function buscar() {

    $query = "SELECT * FROM " . $this->TableName . " WHERE ID_STATUS=1 ORDER BY ORDEN ASC";
    $salida = $this->tovector_assoc_query($query);
    //print($query);
    return $salida;
  }

  /*
   * @return nada si dos campos son iguales a los comparados
   * */

  function unique($Column1, $Value1, $Column2, $Value2) {
    $query = "SELECT * FROM " . $this->TableName . " WHERE " . $Column1 . "=" . $Value1 . " AND " . $Column2 . "=" . $Value2 . " AND ID_STATUS=1";
    $result = $this->runquery($query);
    //print_r($query);
    if ($this->SQLObject->num_rows($result) == 0) {
      return false;
    } else {
      $this->getdata($result);
      return true;
    }
  }

  function buscar_por_marca($id_marca) {

    $query = "SELECT distinct(PRODUCTOS.ID), PRODUCTOS.DESCRIPCION, PRODUCTOS.ORDEN FROM PRODUCTOS, ARTICULOS_PRODUCTOS, ARTICULOS 
              WHERE ARTICULOS_PRODUCTOS.ID_ARTICULO = ARTICULOS.ID AND 
              ARTICULOS_PRODUCTOS.ID_PRODUCTO = PRODUCTOS.ID AND ARTICULOS.ID_MARCA = ".$id_marca." AND 
              PRODUCTOS.ID_STATUS=1 AND ARTICULOS.ID_STATUS = 1 ORDER BY PRODUCTOS.ORDEN ASC, PRODUCTOS.ID ASC";
    $salida = $this->tovector_assoc_query($query);
//    print($query);
    return $salida;
  }

}

?>
